#include "PageLib.h"

#include <dirent.h>
#include <iostream>

PageLib::PageLib(string dirName):_dirName(dirName) {
}
    
void PageLib::create() {
    traverseDir();//把文件名放进vector中
    _fileProcessor.createWeb(_filesName);
    _fileProcessor.createWebOffsetLib(_filesName);
}

void PageLib::traverseDir() {
    DIR *dir;
    struct dirent *entry;

    if((dir = opendir(_dirName.c_str())) != nullptr) {
        while((entry = readdir(dir)) != nullptr) {
            if(entry->d_type = DT_REG && entry->d_name[0] != '.') {
                    _filesName.push_back(entry->d_name);
            }
        }
        closedir(dir);
    }
    else {
        std::cerr << "Failed to open directory" << std::endl;
    }

}

void PageLib::showVec() {
    std::cout << "文件个数为:" << _filesName.size() << std::endl;
    for(auto &elem : _filesName) {
        std::cout << elem << std::endl;
    }
}








